<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:ireaper="http://www.ireaper.net"
                exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>
  <!--<msxsl:script language ="c#" implements-prefix="ireaper">
    <![CDATA[
    public string format_date(string ori)
    {
        if (ori == null)
        {
          return "";
        }
        
        string[] items = ori.Split('-');
        if (items.Length > 0)
        {
          return items[0];
        }
        
        return null;
    }]]>
  </msxsl:script>--> 
    
  <xsl:template match="/">
    <Webcasts>
      <xsl:for-each select =".//R">
        <xsl:apply-templates select="." />
      </xsl:for-each>
    </Webcasts>
  </xsl:template>
  <xsl:template match ="R">
    <R>
      <!--News ID-->
      <newsID>
        <xsl:value-of select="newsID" />
      </newsID>

      <!--Headline-->
      <headline>
        <xsl:value-of select="headline"  disable-output-escaping="no"/>
      </headline>
<!--Description-->
<description>
<xsl:value-of select="description" />
</description>
      <!--Url-->
      <url>
        <xsl:value-of select="url1" disable-output-escaping="yes" />
      </url>

      <xsl:for-each select="a">
        <xsl:choose>
          <!--Level-->
          <xsl:when test="@attCatID=4">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">level</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="@attValue" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Date-->
          <xsl:when test="@attCatID=5">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">date</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="ireaper:format_date(@attValue)" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Speaker-->
          <xsl:when test="@attCatID=6">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">speaker</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="@attValue" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Title-->
          <xsl:when test="@attCatID=10">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">title</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="@attValue" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Resume-->
          <xsl:when test="@attCatID=7">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">resume</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="@attValue" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Products-->
          <xsl:when test="@attCatID=89302">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">products</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="document('attributes.xml')/attributes/C[@attCatID=current()/@attCatID]/V[@attValID=current()/@attValue]/@description" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Technology-->
          <xsl:when test="@attCatID=89303">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">tech</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="document('attributes.xml')/attributes/C[@attCatID=current()/@attCatID]/V[@attValID=current()/@attValue]/@description" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Series-->
          <xsl:when test="@attCatID=60301">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">series</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="document('attributes.xml')/attributes/C[@attCatID=current()/@attCatID]/V[@attValID=current()/@attValue]/@description" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--PPT-->
          <xsl:when test="@attCatID=89304">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">slides</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Video-->
          <xsl:when test="@attCatID=89305">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">video</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Code-->
          <xsl:when test="@attCatID=89306">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">code</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--QA-->
          <xsl:when test="@attCatID=89307">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">qa</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--WMV-->
          <xsl:when test="@attCatID=89310">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">wmv</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--MP4-->
          <xsl:when test="@attCatID=89311">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">mp4</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--MP3-->
          <xsl:when test="@attCatID=89312">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">mp3</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:choose>
                  <xsl:when test="@attValue != ''">1</xsl:when>
                </xsl:choose>
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <!--Rating-->
          <xsl:when test="@attCatID=89309">
            <xsl:element name="a">
              <xsl:attribute name="attCatID">rating</xsl:attribute>
              <xsl:attribute name="attValue">
                <xsl:value-of select="@attValue" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>         
        </xsl:choose>
      </xsl:for-each>
      	<a attCatID="eventID" attValue="" />
    </R>
  </xsl:template>
</xsl:stylesheet>